<script>
import logos from '@/assets/logos.webp'
import { Fold,Expand } from '@element-plus/icons-vue';
import AsideCom from '@/components/AsideCom.vue';
export default{
  data(){
    return{
      url:logos,
      collapse:false
    }
  },
  methods: {
    setCount(){
      this.$store.commit('add')
    },
    logout(){
      localStorage.clear()
      // 退出后清除用户数据
      this.$store.commit('updateUserInfo')
      // 点击退出按钮跳转到登录页面
      this.$router.push('/login')
    }
  },
  mounted() {
    // 判断用户是否登录
    if(!this.$store.state.userInfo.adminname) {
      //用户没有登录
      this.$router.push('/login')
    }
  },
  computed:{
    headerLeft(){
      return this.collapse ? 'Expand' : 'Fold'
    },
    asideWidth(){
      return this.collapse ? '64px' : '230px'
    }
  },
  components:{
    Fold,
    Expand,
    AsideCom
  }
}
</script>

<template>
  <div class="common-layout">
    <el-container>
      <!-- 左侧侧边栏 -->
      <el-aside>
         <div class="logo-box">
          <el-image style="width:50px; height: 50px;" :src="url"></el-image>
           <h2 class="mange-title" v-show="! collapse">乐购后台管理系统</h2>
        </div>
        <!-- collapsa用来判断是否收起侧边栏的值 -->
        <AsideCom :collapse="collapse"></AsideCom>
      </el-aside>
      <el-container>
        <!-- 头部 -->
        <el-header>
          <el-icon size="30" @click="collapse = !collapse">
            <component :is="headerLeft"></component>
          </el-icon>
          <span>欢迎 {{ $store.state.userInfo.adminname }} <button @click="logout">退出</button></span>
        </el-header>
        <!-- 主体内容 -->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style lang="scss" scoped>
.el-container{
  background-color: rgb(239, 243, 243);
  .el-aside{
  background-color: #304156;
  width: v-bind(asideWidth);
  transition: all 0.3s;
  .logo-box{
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    box-sizing: border-box;
     .el-image{
      margin-right: 10px;
     }
    .mange-title{
      font-size: 17px;
    }
  }
}

}
.el-header{
  background-color: #c1d4ea;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

</style>
